#!/bin/bash

echo "\033[33minstalling openssl... \033[0m"

apt install openssl

echo "\033[33minstalling git... \033[0m"
apt install git

echo "\033[33mdownloading hiredis... \033[0m"
git clone https://github.com/redis/hiredis.git

echo "\033[33mmaking hiredis... \033[0m"
cd hiredis
make -j
sudo make install
sudo ldconfig

cd ../

echo "\033[33minstalling nghttp2... \033[0m"
apt install libnghttp2-dev

echo "\033[33mdownloading swoole... \033[0m"

# 这里把 4.0.4 改成你要安装的版本即可
swooleVersion="4.0.4"

wget -O swoole.zip "https://github.com/swoole/swoole-src/archive/v${swooleVersion}.tar.gz"
echo "\033[33mextracting swoole... \033[0m"
tar -zxvf swoole.zip
cd "swoole-src-${swooleVersion}"

#git clone https://gitee.com/swoole/swoole.git
#cd swoole
#git checkout --no-track -b Branch_${swooleVersion} ${swooleVersion} --

echo "\033[33mmaking swoole... \033[0m"

phpize
# 下面的可以根据你的需要修改
./configure --enable-openssl --enable-http2 --enable-async-redis --enable-mysqlnd

# 判断为 wsl，则注释 #define HAVE_SIGNALFD 1
if [[ $(echo `uname -a` | grep "Microsoft") != "" && -d "/mnt/c" ]]
then
  sed -i 's/#define HAVE_SIGNALFD 1/\/\/#define HAVE_SIGNALFD 1/g' config.h
fi

make clean
make -j
sudo make install
